class ItemData {
	public id:number;
	public itemid:number;
	public count:number;
	public level:number;
	public star:number;
	public strong:number;
	public strongTimes:number;
	public itemConf:any;
	public heroid:number;
	public openTime:number;
	public constructor() {
	}
}


class ItemDataMgr {
	public itemDataArray:Array<ItemData> = new Array<ItemData>();
	public constructor() {

	}
	public clear () {
		this.itemDataArray.length = 0;
	}

	public addItemData(data):void {
		console.log('增加物品', data.id, data.itemid, data.count, data.open_time);
		var itemConf = GameMain.me.config.item_conf[data.itemid]
		if (!itemConf) {
			console.error("配置找不到", data.itemid);
			return;
		}
		var item = new ItemData();
		item.id = data.id;
		item.count = data.count;
		item.itemid = data.itemid;
		item.level = data.level;
		item.star = data.star;
		item.strong = data.strong;
		item.strongTimes = data.strong_times;
		item.heroid = data.heroid;
		item.openTime = data.open_time;
		item.itemConf = itemConf;
		this.itemDataArray.push(item);
	}

	public addItem(id:number, itemid:number, count:number):void {
		console.log('增加物品', id, itemid, count);
		for (var k in this.itemDataArray) {
			var item = this.itemDataArray[k];
			if (item.id == id) {
				item.count = item.count + count;
				return;
			}
		}
		var item = new ItemData();
		item.id = id;
		item.count = count;
		item.itemid = itemid;
		item.itemConf = GameMain.me.config.item_conf[itemid];
		this.itemDataArray.push(item);
	}

	public removeItem(id:number, count:number): void {
		for (var k in this.itemDataArray) {
			var item = this.itemDataArray[k];
			if (item.id == id) {
				item.count = item.count - count;
				console.log('删除道具', id, '共', count, '个');
				if (item.count <= 0) {
					console.log('移除道具');
					this.itemDataArray[k] = this.itemDataArray[this.itemDataArray.length - 1];
					this.itemDataArray.pop();
				}
				return;
			}
		}
	}

	public getItem(id:number) {
		for (var k in this.itemDataArray) {
			var itemData = this.itemDataArray[k];
			if (itemData.id == id) {
				return itemData;
			}
		}
	}
}